home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11403 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  57 lines

  1. Path: ix.netcom.com!news
  2. From: rajash@ix.netcom.com(Rajash Gopalakrishnan )
  3. Newsgroups: comp.lang.c++
  4. Subject: Floating Point Error Traping by try and catch:-
  5. Date: 14 Mar 1996 03:18:47 GMT
  6. Organization: Netcom
  7. Message-ID: <4i836n$2u8@dfw-ixnews5.ix.netcom.com>
  8. NNTP-Posting-Host: pal-il3-14.ix.netcom.com
  9. X-NETCOM-Date: Wed Mar 13  9:18:47 PM CST 1996
  10.  
  11. Hi Experts!.
  12.  
  13. We were using normal try and catch statements to trap
  14. the exceptional errors occured during C++ class operation.
  15. We are working on Soaris C++ 4.1 with Toolsh++ classes.
  16.  
  17. Here is a sample program which causes floating point error.
  18. If anybody have a clue, please tell me a method to trap
  19. this error.
  20.  
  21. BOOL Divide_By_Zero();
  22.  
  23. main()
  24. {
  25.   try
  26.   {
  27.   Divide_By_Zero()
  28.   }
  29.   catch(long&)
  30.   {
  31.    cout << 'Got Error' << endl;
  32.   }
  33. }
  34.  
  35. BOOL Divide_By_Zero()
  36. {
  37.   long i,j;
  38.  
  39.   i= 4.0;
  40.  
  41.   j = i/0;  // causing Floating Point Error
  42.  
  43.  return TRUE;
  44. }
  45.  
  46. Here what I found is that before catch, arithemetic experssion fault 
  47. occurs and core is dumping. One method I found is to redirect the
  48. signal
  49. handler and do a catch but that's a round about method. Can anybody 
  50. explain how we can handle this situation by try and catch alone. Is
  51. there
  52. any method to show where error occured and line#.
  53.  
  54. Thanks 
  55. Raj
  56.  
  57.